dump("[WebExtension] content.js loaded!\n"); // 强制输出到系统日志，据说可以，不知怎么用没看到

// 采用立即注入全局隐藏样式（优先级最高），需要manifest.json中 "run_at": "document_start" 配合。  "run_at": "document_start"
const style = document.createElement('style');
style.textContent = `
  #page-head { display: none !important; }
  #bottom-bar { display: none !important; }
  #b_header { display: none !important; }
  #b_footer { display: none !important; }
  #header { display: none !important; }
  #ad_topslot { display: none !important; }
  #aswift_0_host { display: none !important; }
  #footer { display: none !important; }
  #customize-tabs { display: none !important; }
  #header { display: none !important; }
  #body { display: none !important; }
  .Nav_nav__3wFB0 .Nav_black__wI8Tp { display: none !important; }
  .BottomDownload_content__2Rn9Y { display: none !important; }
  .ns-kavve-l-banner-vanilla ns-kavve-v-5 { display: none !important; }


  #results {pointer-events: none !important;}
  #b_content {pointer-events: none !important;}

//  .rt-body{padding-top:0px !important;}
//   #J-attach-bottom-margin + div{display: none !important;}
//  .page-video-list {pointer-events: none !important;}
//  .chain-con .con-img.J-inlink.J-inlink-img {pointer-events: none !important;}

`;
document.documentElement.prepend(style); // 插入到 <html> 的最开始


// 2. 添加 DOMContentLoaded 监听器，等待页面完全加载
document.addEventListener("DOMContentLoaded", () => {
    //console.log("页面加载完成，开始操作 DOM");

    const firstChild = document.querySelector("#J-extra-info").querySelector("li");
    if (firstChild && (
        firstChild.textContent.includes('电影') ||
        firstChild.textContent.includes('小说') ||
        firstChild.textContent.includes('游戏'))) {
        // 如果包含指定字符串，添加样式
//        document.querySelector("#J-second-summary").style.display="none"
//        document.querySelector("#J-second-summary").style="display: none !important;"
        document.querySelector("#J-second-summary").style="pointer-events: none !important;"
        document.querySelector(".full-screen-second_prestrain").style="pointer-events: none !important;"
        document.querySelector(".full-screen-second-container").style="pointer-events: none !important;"
        document.querySelector(".second-play-container").style.display="none"

        document.querySelector(".summary-wrapper").style="pointer-events: none !important;"
        document.querySelector(".summary-link").style="pointer-events: none !important;"
        document.querySelector("#J-sub-menu").style.display="none"

    }
    const desc = document.querySelector("#lemmaDesc");
    if(desc.textContent.includes('游戏')){
        document.querySelector(".swiper-wrapper").style.display="none"
    }
    document.querySelector("#J-declare").style="display: none !important;"
    document.querySelector(".sub-menu").style="display: none !important;"
    document.querySelector("#J-sub-menu").style="display: none !important;"
    document.querySelector(".summary-wrapper").style.display="none"
    document.querySelector(".chain-con .con-img.J-inlink.J-inlink-img").style="pointer-events: none !important;"
    //主演
    const actor = document.querySelector("#J-sub-menu").querySelector("a");
    if(actor && (actor.textContent.includes('主演'))){
        document.querySelector(".summary-wrapper").style="pointer-events: none !important;";
        document.querySelector(".summary-link").style="pointer-events: none !important;";
        document.querySelector("#J-sub-menu").style.display="none";
    }
    const spatial = document.querySelector(".authority-list");
    if(spatial) spatial.style.display="none";

    //他说
    const tashuo2 = document.querySelector(".floatTashuo-list-wrapper");
    if(tashuo2) tashuo2.style.display="none";
    const tashuo3 = document.querySelector(".tashuo-list");
    if(tashuo3) tashuo3.style.display="none";


    //剧情解析
    const jqjx = document.querySelector(".tashuo-inContent");
    if(jqjx) jqjx.style.display="none";

    //百科后面的
    const bkafter = document.querySelector(".BK-after-content-wrapper");
    if(bkafter) bkafter.style.display="none";


});



////
//function hideElement() {
////    const element = document.querySelector("#BK_before_content_wrapper");
////    if (element) {
////        element.remove();
////    }
//    const ele2 = document.querySelector(".quickNav");
//    if(ele2) ele2.remove();
//    const ele3 = document.querySelector(".rt-head");
//    if(ele3) ele3.remove();
//    const ele4 = document.querySelector(".rt-body");
//    if(ele4) ele4.style.paddingTop="0px";
//
//    const ele5 = document.querySelector("#J-editentrance");//编辑词条那个
//    if(ele5) ele5.remove();
//    //
//    const ele6 = document.querySelector("#tashuo_list");
//    if(ele6) ele6.remove();
//
//    const ele7 = document.querySelector(".copyright");
//    if(ele7) ele7.remove();
//
//    const ele8 = document.querySelector("#bottomMenu");
//    if(ele8) ele8.remove();
//    const ele9 = document.querySelector(".bottom-logo");
//    if(ele9) ele9.remove();
//
//    const ele10 = document.querySelector("#J-catalog-button-fixed");
//    if(ele10) ele10.remove();
//    const ele11 = document.querySelector("#J-tashuo-button-fixed");
//    if(ele11) ele11.remove();
//
//    //有个广告在这个节点  下一个
//    const ele12 = document.querySelector("#J-attach-bottom-margin");
//    if(ele12) {
//        const nextDom = ele12.nextElementSibling;
//        if(nextDom){nextDom.remove();}
//    }
//
//}
//
//// 直接执行（无需等待消息）
//hideElement();
//
//// 或者监听端口消息（动态控制）
//browser.runtime.onConnect.addListener((port) => {
//    console.log("Port connected:", port.name); // 调试连接是否建立
//
//    port.onMessage.addListener((msg) => {
//        if (msg.action === "hideElement") {
//            hideElement();
//            port.postMessage({ success: true });
//        }
//    });
//});
